#-------------------------------------------------------------------------------
# Name:        broadcast frame
#-------------------------------------------------------------------------------
#!/usr/bin/env python

def create(parent, initial_broadcast, initial_msg):
    broadcastFrame = tk.Frame(parent)

    broadcastChatBox = tk.Text(broadcastFrame, height=3)
    broadcastChatBox.insert(tk.INSERT, initial_broadcast)
    broadcastChatBox['state'] = 'disabled'
    broadcastChatBox.pack()

    broadcastMsg = tk.StringVar()
    broadcastEntryBox = tk.Entry(broadcastFrame, text=initial_msg, textvariable=broadcastMsg)
    broadcastEntryBox.pack()

    broadcastSubmitButton = tk.Button(broadcastFrame, text = "Submit", command=create_send_broadcast_command(broadcastMsg, broadcastChatBox)).pack()

    return broadcastFrame

def send_broadcast_msg(strvar, broadcast_out):
    if not strvar.get():
        return

    broadcast_out['state'] = 'normal'
    broadcast_out.insert(tk.END, '\n' + strvar.get())
    broadcast_out.see(tk.END)
    broadcast_out['state'] = 'disabled'
    strvar.set('')

def create_send_broadcast_command(strvar, broadcast_out):
    return lambda:send_broadcast_msg(strvar, broadcast_out)